<template>
    <div class="">
    <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-message"></i> 用户列表</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
        	<el-form :inline="true"  class="demo-form-inline">
        		<el-form-item label="手机:">
                        <el-input v-model="mobile" placeholder="请输入用户手机" clearable style="width:200px;"></el-input>
            </el-form-item>
            <el-form-item label="昵称:">
                        <el-input v-model="nickname" placeholder="请输入用户昵称" clearable style="width:200px;"></el-input>
            </el-form-item>
    			<el-form-item label="性别:">
                	<el-select v-model="valuegender" placeholder="性别" >
					    <el-option
					      v-for="item in optionsGender"
					      :key="item.value"
					      :label="item.label"
					      :value="item.value">
					    </el-option>
					  </el-select>
					 </el-form-item> 
					 <el-form-item label="是否企业用户：">
                	<el-select v-model="valuePrise" placeholder="是否企业用户" >
					    <el-option
					      v-for="item in optionsPrise"
					      :key="item.value"
					      :label="item.label"
					      :value="item.value">
					    </el-option>
					  </el-select>
					 </el-form-item> 
					 <el-form-item label="是否为冻结用户：">
                	<el-select v-model="valueDisabled" placeholder="是否为冻结用户" >
					    <el-option
					      v-for="item in optionsDisabled"
					      :key="item.value"
					      :label="item.label"
					      :value="item.value">
					    </el-option>
					  </el-select>
					 </el-form-item> 
					 <el-form-item>
                        <el-button type="primary" @click="onSelect"> &nbsp;&nbsp;查询&nbsp;&nbsp;  </el-button>
                        </el-form-item> 
			</el-form>		
			
                        <!-- <el-button type="primary" @click="onResetting"> &nbsp;&nbsp;重置&nbsp;&nbsp;  </el-button> -->
            <!-- </el-form-item> -->
            <div style="height:40px"></div>
                <el-table :data="tableData"  style="width: 100%"   ref="multipleTable">
                    <el-table-column prop="id" label="用户ID" width="100" align="center">
                    </el-table-column>
                    <el-table-column prop="mobile" label="手机" width="300" align="center">
                    </el-table-column>
                    <el-table-column label="头像" width="200" align="center">
                        <template slot-scope="scope" >
                            <div><img :src="scope.row.logo" style="width:100px;height:100px"></div>
                        </template>
                    </el-table-column>
                    <el-table-column prop="nick_name" label="昵称" width="200" align="center">
                    </el-table-column>
                    <el-table-column prop="trans_gender" label="性别" width="200" align="center">
                    </el-table-column>
                    <el-table-column prop="trans_is_enterprise" label="是否企业用户" width="200" align="center">
                    </el-table-column>
                    
                    <el-table-column  label="是否冻结用户" width="300" align="center">
                    	<template slot-scope="scope" >
	                    	<el-switch
							  v-model="scope.row.is_disabled"
							  :active-value="1"
							  :inactive-value="0"
							  active-text="是"
							  inactive-text="否"
							  @change="toSetRecommend(scope.$index, scope.row)">
							</el-switch>
						</template>
                    </el-table-column>
                    
                </el-table>
                
                <div class="pagination" v-show="totalPages>1">
                    <el-pagination @current-change="handleCurrentChange" layout="prev, pager, next" :page-size="pageSize" :total="totalElements" background>
                    </el-pagination>
                </div>
                
        </div>
        
        <!-- 删除提示框 -->
        <!-- <el-dialog title="提示" :visible.sync="delVisible" width="300px" center>
            <div class="del-dialog-cnt">删除不可恢复，是否确定删除？</div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="delVisible = false">取 消</el-button>
                <el-button type="primary" @click="deleteRow">确 定</el-button>
            </span>
        </el-dialog> -->
        <!-- / 删除提示框 -->
    </div>
</template>
<script>
import {userList,userIsHot,userIsCool} from '@/api/user'
export default {
    name:"usermanage",
    data() {
        return {
            pageIndex:1,//当前页码
            pageSize:10,//每页10条
            totalElements:1,//默认总条数
            totalPages:1,//默认总页数
            tableData:[],//表格数据
            delIndex:0, //当前选中的下标
            delId:0,  //当前要删除的Id
            delVisible:false, //默认dialog 不弹出
            type:0,
            optionsGender: [{
			          value: ' ',
			          label: '全部'
			        }, {
			          value: '1',
			          label: '男'
			        }, {
			          value: '2',
			          label: '女'
			        }],
	        valuegender: ' ',//性别
	        optionsDisabled: [{
			          value: ' ',
			          label: '全部'
			        }, {
			          value: '0',
			          label: '否'
			        }, {
			          value: '1',
			          label: '是'
			        }],
	        valueDisabled: ' ',//是否禁用
	        optionsPrise: [{
			          value: ' ',
			          label: '全部'
			        }, {
			          value: '0',
			          label: '否'
			        }, {
			          value: '1',
			          label: '是'
			        }],
	        valuePrise: ' ',//是否企业用户
	        mobile:"",//手机
	        nickname:"",//昵称
	        }
    },
    //实例创建
    created(){
        //
        this.getList();
    },
    //计算属性
    computed:{
    	
    },
    //方法
    methods: {
    	//switch改变事件
    	toSetRecommend(index,row){
    		console.log(index,row);
    		var state = row.is_disabled;
    		var id = [];
    		id.push(row.id);
    		console.log(state,"状态");
    		if(state == 1){
    			this.toRecomment(id,index);
    		}else{
    			this.toRecommentNo(id,index);
    		}
    	},
    	//冻结
    	toRecomment(id,index){
    		userIsCool(id).then((response) => {
                if(response.code==200){
                    var data = response.data;//当前返回的数据
					this.$message.success('冻结成功');
                }else{
                    this.$notify.error({
                        title: '异常',
                        offset: 100,
                        message: response.msg
                    });
                }
        	})
    	},
    	//取消冻结
    	toRecommentNo(id,index){
    		userIsHot(id).then((response) => {
                if(response.code==200){
                    var data = response.data;//当前返回的数据
					this.$message.success('取消冻结成功');
                }else{
                    this.$notify.error({
                        title: '异常',
                        offset: 100,
                        message: response.msg
                    });
                }
        	})
    	},
        //获取协会列表
        getList(){
        	var param = {
        		mobile:this.mobile,
				nickName:this.nickname,
				gender:this.valuegender,
				isDisabled:this.valueDisabled,
				isEnterprise:this.valuePrise,
				pageIndex:this.pageIndex,
				pageSize:this.pageSize
        	}
        	userList(param).then((response) => {
                if(response.code==200){
                    var data = response.data;//当前返回的数据
                    this.tableData = data.list;//列表数据
                    this.totalElements = data.total; //总条数
                    this.totalPages = Math.ceil(data.total/this.pageSize);//总页数
                }else{
                    this.$notify.error({
                        title: '异常',
                        offset: 100,
                        message: response.msg
                    });
                }
        	})
        },
        //分页
        handleCurrentChange(val){
            this.pageIndex =val;
            this.getList();
        },
        //查询
        onSelect(){
            this.pageIndex =1;
            this.getList();
        },
        
    }
}
</script>
<style lang="stylus" scoped>
	.edit{
	    color #ff9800;
	}
	.del{
	    color #e51c23;
	}
	.download{
	    color #67C23A;
	}
</style>


